package com.siae.controller;


import com.siae.pojo.Role;
import com.siae.pojo.vo.Result;
import com.siae.service.RoleService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Tag(name = "RoleController",description = "用户角色操作")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping
    public Result<List<Role>> getAllRoles(@RequestParam (value = "userRole",defaultValue = "") String userRole){
        return roleService.getAllRoles(userRole);
    }
    @GetMapping("/{id}")
    public Result<Role> getRoleById(@PathVariable("id") Integer id){
        return roleService.getRoleById(id);
    }
    @GetMapping("/name/{name}")
    public Result<Role> getRoleByName(@PathVariable("userRole") String userRole){
        return roleService.getRoleByName(userRole);
    }
    @PostMapping
    public Result addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }
    @PutMapping
    public Result updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }
    @DeleteMapping("/{id}")
    public Result deleteRole(@PathVariable("id") Integer id){
        return roleService.deleteRole(id);
    }
}
